home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Tracker.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.8 KB  |  341 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Tracker.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. #ifndef TRACKER_H
  13. #include "Tracker.h"
  14. #endif
  15.  
  16. #ifndef VIEW_H
  17. #include "View.h"
  18. #endif
  19.  
  20. #ifndef CONTENT_H
  21. #include "Content.h"
  22. #endif
  23.  
  24. #ifndef VIEW_H
  25. #include "View.h"
  26. #endif
  27.  
  28. // ----- Part Layer -----
  29.  
  30. #ifndef FWUTIL_H
  31. #include "FWUtil.h"
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35.  
  36. #ifndef FWODGEOM_H
  37. #include "FWODGeom.h"
  38. #endif
  39.  
  40. #ifndef FWACQUIR_H
  41. #include "FWAcquir.h"
  42. #endif
  43.  
  44. #ifndef FWPOINT_H
  45. #include "FWPoint.h"
  46. #endif
  47.  
  48. #ifndef FWCONTXT_H
  49. #include "FWContxt.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Layer -----
  53.  
  54. #ifndef SOM_ODSession_xh
  55. #include <ODSessn.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODDragAndDrop_xh
  59. #include <DragDrp.xh>
  60. #endif
  61.  
  62. //========================================================================================
  63. // RunTime Info
  64. //========================================================================================
  65.  
  66. #ifdef FW_BUILD_MAC
  67. #pragma segment odfTable
  68. #endif
  69.  
  70. //========================================================================================
  71. //    class CTableDropTracker
  72. //========================================================================================
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    CTableDropTracker::CTableDropTracker
  76. //----------------------------------------------------------------------------------------
  77.  
  78. CTableDropTracker::CTableDropTracker(Environment* ev, 
  79.                                     CTablePart* part,
  80.                                     CTablePartContent* content,
  81.                                     CTableView* view,
  82.                                     ODFacet* facet,
  83.                                     const CCell& sourceCell) :
  84.     FW_CDropTracker(ev, view, facet, TRUE),
  85.     fTableView(view),
  86.     fTablePart(part),
  87.     fTableContent(content),
  88.     fSourceCell(sourceCell),
  89.     fCurCell(-1, -1)
  90. {
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    CTableDropTracker::~CTableDropTracker
  95. //----------------------------------------------------------------------------------------
  96.  
  97. CTableDropTracker::~CTableDropTracker()
  98. {
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    CTableDropTracker::ShouldHilite
  103. //----------------------------------------------------------------------------------------
  104. // Because I don't want to drop on a cell already containing a proxy
  105.  
  106. FW_Boolean CTableDropTracker::ShouldHilite(Environment* ev, const FW_CPoint& point, CCell& cell)
  107. {
  108.     return (fTableContent->HitTest(ev, point, cell) == kTLCell) && (fTableContent->CellToProxy(cell) == NULL);
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    CTableDropTracker::BeginTracking
  113. //----------------------------------------------------------------------------------------
  114.  
  115. FW_CPoint CTableDropTracker::BeginTracking(Environment* ev, 
  116.                                             const FW_CPoint& anchorPoint)
  117. {
  118.     CCell cell;
  119.     
  120.     if (ShouldHilite(ev, anchorPoint, cell))
  121.         Hilite(ev, cell, GetFacet(ev));
  122.     
  123.     return anchorPoint;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    CTableDropTracker::ContinueTracking
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_CPoint CTableDropTracker::ContinueTracking(Environment* ev,
  131.                                                 const FW_CPoint& anchorPoint, 
  132.                                                 const FW_CPoint& previousPoint, 
  133.                                                 const FW_CPoint& currentPoint)
  134. {
  135. FW_UNUSED(anchorPoint);
  136. FW_UNUSED(previousPoint);
  137.     CCell cell;
  138.     if (ShouldHilite(ev, currentPoint, cell))
  139.         Hilite(ev, cell, GetFacet(ev));
  140.     else
  141.     {
  142.         fCurCell = CCell(-1, -1);
  143.         this->HideDragHilite(ev);
  144.     }
  145.         
  146.     return currentPoint;
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    CTableDropTracker::Hilite
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CTableDropTracker::Hilite(Environment* ev, const CCell& cell, ODFacet* facet)
  154. {
  155.     if (cell == fCurCell)
  156.         return;
  157.     
  158.     fCurCell = cell;
  159.  
  160. #ifdef FW_BUILD_MAC
  161.     this->HideDragHilite(ev);
  162.  
  163.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  164.  
  165.     if (cell != fSourceCell)
  166.     {    
  167.         FW_CRect cellRect;
  168.         fTableContent->FindRect(cell, cellRect);
  169.         
  170.         FW_CRect shapeBounds = fTableView->GetBoundsInContent(ev);
  171.         cellRect.Intersection(shapeBounds);
  172.         fTableView->ViewContentToFrame(ev,     cellRect);
  173.         
  174.         FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, cellRect);
  175.  
  176.         this->ShowDragHilite(ev, aqShape, TRUE);
  177.     }
  178. #endif
  179. }
  180.  
  181. //========================================================================================
  182. //    class CGridLineTracker
  183. //========================================================================================
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    CGridLineTracker constructor
  187. //----------------------------------------------------------------------------------------
  188. CGridLineTracker::CGridLineTracker(Environment* ev, 
  189.                                      FW_CView* view,
  190.                                     ODFacet* facet,
  191.                                        ETableLoc tl,
  192.                                        FW_CRect dragArea,
  193.                                        FW_CPoint borders) :
  194.     FW_CTracker(ev, view, facet),
  195.     fDragArea(dragArea),
  196.     fOldBorders(borders),
  197.     fNewBorders(borders),
  198.     fCross(borders, dragArea.BotRight())
  199. {
  200.     // Get direction of resize
  201.     fHorizMove = ((tl & (kTLLeftBorder + kTLRightBorder)) != 0);
  202.     fVertMove = ((tl & (kTLTopBorder + kTLBottomBorder)) != 0);
  203.  
  204.     if (fHorizMove)
  205.         fCross.SetVLineToMove();
  206.     if (fVertMove)
  207.         fCross.SetHLineToMove();
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    CGridLineTracker destructor
  212. //----------------------------------------------------------------------------------------
  213. CGridLineTracker::~CGridLineTracker()
  214. {
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //    CGridLineTracker::BeginTracking
  219. //----------------------------------------------------------------------------------------
  220. FW_CPoint CGridLineTracker::BeginTracking(Environment* ev, 
  221.                                           const FW_CPoint& anchorPoint)
  222. {
  223.     // Display borders that are moving
  224.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  225.     fCross.Render(vc);
  226.  
  227.     return anchorPoint;
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    CGridLineTracker::ContinueTracking
  232. //----------------------------------------------------------------------------------------
  233. FW_CPoint CGridLineTracker::ContinueTracking(Environment* ev,
  234.                                              const FW_CPoint& anchorPoint, 
  235.                                              const FW_CPoint& previousPoint, 
  236.                                              const FW_CPoint& currentPoint)
  237. {
  238.     FW_UNUSED(anchorPoint);
  239.     FW_CPoint now(currentPoint);
  240.  
  241.     // Stay in permissible drag area
  242.     if (now.x < fDragArea.left)
  243.         now.x = fDragArea.left;
  244.     if (now.x > fDragArea.right)
  245.         now.x = fDragArea.right;
  246.     if (now.y < fDragArea.top)
  247.         now.y = fDragArea.top;
  248.     if (now.y > fDragArea.bottom)
  249.         now.y = fDragArea.bottom;
  250.  
  251.     // Move the borders
  252.     if (now != previousPoint)
  253.     {
  254.         FW_Fixed x = (fHorizMove ? now.x - previousPoint.x : FW_IntToFixed(0));
  255.         FW_Fixed y = (fVertMove ? now.y - previousPoint.y : FW_IntToFixed(0));
  256.         
  257.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  258.         fCross.Render(vc);
  259.         fCross.MoveShape(x, y);
  260.         fCross.Render(vc);
  261.         
  262.         fNewBorders.x += x;
  263.         fNewBorders.y += y;
  264.     }
  265.  
  266.     return now;
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. //    CGridLineTracker::EndTracking
  271. //----------------------------------------------------------------------------------------
  272. FW_Boolean CGridLineTracker::EndTracking(Environment* ev,
  273.                                          const FW_CPoint& anchorPoint, 
  274.                                          const FW_CPoint& lastPoint)
  275. {
  276.     // Restore the borders
  277.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  278.     fCross.Render(vc);
  279.  
  280.     return anchorPoint != lastPoint;
  281. }
  282.  
  283. //========================================================================================
  284. //    class CCrossShape
  285. //========================================================================================
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    CCrossShape::CCrossShape
  289. //----------------------------------------------------------------------------------------
  290.  
  291. CCrossShape::CCrossShape(const FW_CPoint& brCell, FW_CPoint& brFrm)
  292.     : vLine(brCell.x, FW_kFixed0, brCell.x, brFrm.y),
  293.       hLine(FW_kFixed0, brCell.y, brFrm.x, brCell.y)
  294. {
  295.     vLine.SetInk(FW_kInvertInk);
  296.     hLine.SetInk(FW_kInvertInk);
  297.     
  298.     vLine.SetRenderVerb(FW_kNoRendering);
  299.     hLine.SetRenderVerb(FW_kNoRendering);
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    CCrossShape::Render
  304. //----------------------------------------------------------------------------------------
  305.  
  306. void CCrossShape::Render(FW_CGraphicContext& graphicContext)
  307. {
  308.     vLine.Render(graphicContext);
  309.     hLine.Render(graphicContext);
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    CCrossShape::MoveShape
  314. //----------------------------------------------------------------------------------------
  315.  
  316. void CCrossShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  317. {
  318.     vLine.MoveShape(deltaX, FW_IntToFixed(0));
  319.     hLine.MoveShape(FW_IntToFixed(0), deltaY);
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    CCrossShape::SetHLineToMove
  324. //----------------------------------------------------------------------------------------
  325.  
  326. void CCrossShape::SetHLineToMove()
  327. {
  328.     hLine.SetRenderVerb(FW_kFrame);
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    CCrossShape::SetVLineToMove
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void CCrossShape::SetVLineToMove()
  336. {
  337.     vLine.SetRenderVerb(FW_kFrame);
  338. }
  339.  
  340.  
  341.